<div class="tabbable tabs-left">
    <ul class="nav nav-tabs">
        <li><h5><?php echo $this->translate('DBShopApi'); ?></h5></li>
        <li class="active"><a data-toggle="tab" href="#dbshopapi_a"><?php echo $this->translate('基本设置'); ?></a></li>
    </ul>
    <form class="form-horizontal" name="dbshopapi_form" id="dbshopapi_form" method="post">
        <div class="tab-content">
            <div id="sticky_navigation" style="height:30px;border-bottom:4px solid #DFDFDF;">
                <div class="pull-left" style="font-size:16px;line-height:30px;"><strong><?php echo $this->translate('DBShop的Api设置'); ?></strong></div>
                <div class="pull-right">
                    <a href="<?php echo $this->serverUrl(true); ?>" class="btn btn-small btn-warning"><i class="icon-repeat icon-white"></i> <?php echo $this->translate('刷新'); ?></a>
                    &nbsp;<button type="submit" class="btn btn-small btn-primary"><i class="icon-ok icon-white"></i> <?php echo $this->translate('保存设置'); ?></button>
                    &nbsp;<a href="http://help.dbshop.net/index.php/DBShop%E7%9A%84API%E6%8E%A5%E5%8F%A3" target="_blank" class="btn btn-small btn-info"><i class="icon-info-sign icon-white"></i> <?php echo $this->translate('查看API接口调用教程'); ?></a>
                </div>
            </div>
            <div id="dbshopapi_a" class="tab-pane active">
                <div class="well admin_add_header_well"><?php echo $this->translate('基本设置'); ?></div>
                <div class="well admin_add_well">
                    <div class="message_one">
                    </div>
                    <div class="control-group">
                        <label for="input01" class="control-label"><?php echo $this->translate('API调用地址'); ?>：</label>
                        <div class="controls">
                            <label style="line-height: 30px;">
                                <?php echo $this->frontwebsite()->dbshopHttpOrHttps().$this->frontwebsite()->dbshopHttpHost() . $this->url('jsonapi/default'); ?>
                            </label>
                        </div>
                    </div>
                    <div class="control-group">
                        <label for="input01" class="control-label"><?php echo $this->translate('扩展API调用地址'); ?>：</label>
                        <div class="controls">
                            <label style="line-height: 30px;">
                                <?php echo $this->frontwebsite()->dbshopHttpOrHttps().$this->frontwebsite()->dbshopHttpHost() . $this->url('extendapi/default'); ?>
                            </label>
                        </div>
                    </div>
                    <div class="control-group">
                        <label for="input01" class="control-label"><?php echo $this->translate('API 密钥'); ?><span class="must_add_value">*</span>：</label>
                        <div class="controls">
                            <input type="text" name="dbshop_api_key" id="dbshop_api_key" value="<?php if(isset($this->api['apiKey']) and !empty($this->api['apiKey'])) echo $this->api['apiKey']; ?>" class="span4">
                            <button type="button" class="btn btn-primary btn-small" onclick="create_api_key();"><?php echo $this->translate('点击自动创建'); ?></button>
                        </div>
                    </div>
                    <div class="control-group">
                        <label for="input01" class="control-label"><?php echo $this->translate('API状态'); ?><span class="must_add_value">*</span>：</label>
                        <div class="controls">
                            <label class="checkbox inline">
                                <input type="checkbox" name="dbshop_api_state" id="dbshop_api_state" value="1" <?php if(isset($this->api['dbshopApiState']) and $this->api['dbshopApiState'] == 1) echo 'checked'; ?>><?php echo $this->translate('启用'); ?>
                            </label>
                        </div>
                    </div>

                </div>
            </div>

        </div>
    </form>
</div>
<script>
    <?php if ($this->success_msg != '') { ?>
    show_message('.message_one','<?php echo date("Y-m-d H:i:s"); ?>','<?php echo $this->success_msg; ?>','alert-success');
    <?php } ?>

    $(document).ready(function() {
        $("#dbshopapi_form").validate({
            rules: {
                dbshop_api_key: {
                    required: true,
                    minlength:10
                }
            },
            messages: {
                dbshop_api_key: {
                    required: "<?php echo $this->translate('API 密钥不能为空！'); ?>",
                    minlength: "<?php echo $this->translate('密钥最少10位！'); ?>"
                }
            }
        });
    });

    function create_api_key() {
        $.get('<?php echo $this->url('dbapi/default', array('action'=>'ajaxCreateKey')); ?>',{}, function(data){
            if(data != '') {
                $('#dbshop_api_key').val(data);
            }
        });
    }
</script>